package eu.jk.web.kits;

import java.net.InetAddress;
import java.net.UnknownHostException;

import javax.servlet.http.HttpServletRequest;
/**
 * 获取客户端信息
 * @author wenjianwzz
 * @version 0.5 
 */
public class ClientAnalyst {
	/**
	 * 获取IP
	 * @return IP
	 */
	public static String getIpAddr(HttpServletRequest request) {
		String ip = request.getHeader("x-forwarded-for");
		if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
			ip = request.getHeader("Proxy-Client-IP");
		}
		if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
			ip = request.getHeader("WL-Proxy-Client-IP");
		}
		if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
			ip = request.getRemoteAddr();
		}
		return ip;
	}
	
	public static String resolveDomain(String domain){
		InetAddress address = null;
		try {
			address = InetAddress.getByName(domain);
		} catch (UnknownHostException e) {
			e.printStackTrace();
			return null;
		}
		return address.getHostAddress();
	}
	
	public static void main(String[] args){
		System.out.println(resolveDomain("www.baidu.com"));
	}
}
